package com.yq.admin.util;

import com.yq.admin.vo.ProductVO;
import com.yq.api.dto.ProductTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhouyanqun on 2016/8/12.
 */
public class ProductTOUtil {
    public static ProductTO toProductTO(ProductVO productVO){
        if(productVO == null){
            return null;
        }
        ProductTO productTO = new ProductTO();
        BeanUtils.copyProperties(productVO, productTO);
        return productTO;
    }

    /**
     * 回写产品信息
     * */
    public static void writeBack(ProductTO productTO, ProductVO productVO){
        if(productTO == null || productVO == null){
            return;
        }
        BeanUtils.copyProperties(productTO, productVO);
    }

    public static ProductVO toProductVO(ProductTO productTO) {
        if(productTO == null){
            return null;
        }
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(productTO, productVO);
        return productVO;
    }

    public static List<ProductVO> toProductVOList(List<ProductTO> productTOList) {
        if(CollectionUtils.isEmpty(productTOList)){
            return null;
        }
        List<ProductVO> productVOList = new ArrayList<ProductVO>();
        for (ProductTO productTO : productTOList) {
            ProductVO productVO = toProductVO(productTO);
            productVOList.add(productVO);
        }
        return productVOList;
    }
}
